home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / ufs / dir.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  4.3 KB  |  101 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    from: @(#)dir.h    7.10 (Berkeley) 3/25/91
  34.  *    $Id: dir.h,v 1.3 1993/05/20 03:53:21 cgd Exp $
  35.  */
  36.  
  37. #ifndef _UFS_DIR_H_
  38. #define _UFS_DIR_H_
  39.  
  40. /*
  41.  * A directory consists of some number of blocks of DIRBLKSIZ
  42.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  43.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  44.  *
  45.  * Each DIRBLKSIZ byte block contains some number of directory entry
  46.  * structures, which are of variable length.  Each directory entry has
  47.  * a struct direct at the front of it, containing its inode number,
  48.  * the length of the entry, and the length of the name contained in
  49.  * the entry.  These are followed by the name padded to a 4 byte boundary
  50.  * with null bytes.  All names are guaranteed null terminated.
  51.  * The maximum length of a name in a directory is MAXNAMLEN.
  52.  *
  53.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  54.  * a directory entry.  Free space in a directory is represented by
  55.  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  56.  * in a directory block are claimed by the directory entries.  This
  57.  * usually results in the last entry in a directory having a large
  58.  * dp->d_reclen.  When entries are deleted from a directory, the
  59.  * space is returned to the previous entry in the same directory
  60.  * block by increasing its dp->d_reclen.  If the first entry of
  61.  * a directory block is free, then its dp->d_ino is set to 0.
  62.  * Entries other than the first in a directory do not normally have
  63.  * dp->d_ino set to 0.
  64.  */
  65. #define DIRBLKSIZ    DEV_BSIZE
  66. #define    MAXNAMLEN    255
  67.  
  68. struct    direct {
  69.     u_long    d_ino;            /* inode number of entry */
  70.     u_short    d_reclen;        /* length of this record */
  71.     u_short    d_namlen;        /* length of string in d_name */
  72.     char    d_name[MAXNAMLEN + 1];    /* name with length <= MAXNAMLEN */
  73. };
  74.  
  75. /*
  76.  * The DIRSIZ macro gives the minimum record length which will hold
  77.  * the directory entry.  This requires the amount of space in struct direct
  78.  * without the d_name field, plus enough space for the name with a terminating
  79.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  80.  */
  81. #define DIRSIZ(dp) \
  82.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  83.  
  84. /*
  85.  * Template for manipulating directories.
  86.  * Should use struct direct's, but the name field
  87.  * is MAXNAMLEN - 1, and this just won't do.
  88.  */
  89. struct dirtemplate {
  90.     u_long    dot_ino;
  91.     short    dot_reclen;
  92.     short    dot_namlen;
  93.     char    dot_name[4];        /* must be multiple of 4 */
  94.     u_long    dotdot_ino;
  95.     short    dotdot_reclen;
  96.     short    dotdot_namlen;
  97.     char    dotdot_name[4];        /* ditto */
  98. };
  99.  
  100. #endif /* !_UFS_DIR_H_ */
  101.